<?php
/**
 * 汽车逻辑类
 * @author zengnz
 *
 */
class CarLogic extends CommonModel
{
	// 所有汽车品牌
	const ALL_BRAND = 'ALL_BRAND';
	
	// 所有汽车车型
	const ALL_CATEGORY = 'ALL_CATEGORY';
	
	// 缓存模型类
	private $_CacheModel = '';
	
	public function __construct() {
		$this -> _CacheModel = D('Cache', 'Service');
		$this -> _CacheModel -> init();
	}
	
	// 获取所有汽车品牌
	public function getAllBrand() {
		$key = self::ALL_BRAND;
		$brand = $this -> _CacheModel -> get($key);
		if (!$brand) {
			
			
		}
		
		return $brand;
	}
	
	// 获取所有汽车车型
	public function getAllCategory() {
		
		
	}
	
	/**
	 * 获取品牌百科
	 * @param integer $brandId
	 */
	public function getBrandPaike($brandId) {
		$info = D('CarBrandPaike') -> where('brand_id='.$brandId)
				-> find();
		
		return $info;
	}
	
	/**
	 * 保存品牌百科信息
	 * @param integer $id
	 * @param array $info
	 */
	public function saveBrandPaike($id,$info) {
		$record = $this -> getBrandPaike($id);
		$Model = D('CarBrandPaike');
		
		if (!$record) {
			$info['create_time'] = time();
			$info['creator_id'] = $this -> getLoginId();
			$info['creator'] = $this -> getAccount();
			
			$ret = $Model -> add($info);
		} else {
			$info['update_time'] = time();
			$info['updator_id'] = $this -> getLoginId();
			$info['edit_times'] = $record['edit_times'] + 1;
			
			$ret = $Model -> where('brand_id='.$id) -> save($info);
		}
		
		return $ret;
	} 
	
}